package com.xcity.game.activity.newplayer.tracer;

import java.text.MessageFormat;

import com.xcity.game.activity.newplayer.NewPlayerDoingStr;
import com.xcity.game.activity.newplayer.NewPlayerTask;
import com.xcity.game.activity.newplayer.NewPlayerTracer;
import com.xcity.game.activity.newplayer.NewPlayerTracerLabel;

import naga.x.game.time.TimeUpdater;
import naga.x.util.TimeUtils;

@NewPlayerTracerLabel(NewPlayerTracer.DAY_LOGIN)
public class DayLoginTracer implements NewPlayerTracer {

	@Override
	public boolean isDone(NewPlayerTask task) {
		if(task.getProgress()[0] == 1){
			return true;
		}
		return false;
	}

	@Override
	public void onChange(NewPlayerTask task, Object... vals) {
		int today = TimeUpdater.getInstance().today();
		int startDay = TimeUtils.getDayGap(task.getVm().getCreatDay(), today) + 1;//today - task.getVm().getCreatDay() + 1;
		if(startDay > 0){
			if(startDay == task.getTemplate().getParam()[1]){
				task.getProgress()[0] = 1;
				task.getProgress()[1] = startDay;
			}
		}
	}

	@Override
	public String getDoingStr(NewPlayerTask task) {
		return MessageFormat.format(NewPlayerDoingStr.STR_DAY_LOGIN, task.getTemplate().getParam()[1]/*, task.getProgress()[0], task.getTemplate().getParam()[0]*/);
	}

}
